<template>
  <div class="patient-detail-container">
    <van-nav-bar
      class="app-nav-bar"
      title="就诊人信息"
      left-arrow
      @click-left="$router.back()"
    />
    <van-form @submit="onSubmit">
      <van-field
        v-model="patient.name"
        disabled
        name="就诊人姓名"
        label="就诊人姓名"
        placeholder="就诊人姓名"
      />

      <van-field
        v-model="certificateName"
        disabled
        name="证件类型"
        label="证件类型"
        placeholder="证件类型"
      />

      <van-field
        v-model="patient.certificatesNo"
        name="证件号"
        label="证件号"
        disabled
        placeholder="证件号"
      />
      <van-field
        v-model="patient.phone"
        name="手机号"
        label="手机号"
        placeholder="手机号"
      />
      <van-field
        v-model="patient.address"
        name="详细住址"
        label="详细住址"
        placeholder="详细住址"
      />
      <van-field
        v-model="patient.cardNo"
        name="就诊卡号"
        label="就诊卡号"
        placeholder="就诊卡号"
        disabled
      />
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit">修改</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import {mapState} from "vuex";
import patientApi from '@/api/patient'
import dictApi from "@/api/dict"

export default {
  name: "PatientDetailIndex",
  data(){
    return{
      patient:{},
      certificateName:''
    }
  },
  created() {
    this.init()
  },
  computed:{
    ...mapState(['user'])
  },
  methods:{
    async init(){
      const id = this.$route.query.id
      await this.getPatientInfo(id)
      await this.getCertificateName()
    },
    async getPatientInfo(id){
      const {data:res} = await patientApi.findById(id)
      this.patient = res.data
    },
    async getCertificateName(){
      const {data:res} = await dictApi.getDictName(this.patient.certificatesType)
      this.certificateName = res
    },
    async onSubmit(){
      const{data:res} = await patientApi.update(this.patient)
      if (res.code!=200){
        return this.$notify({type:'danger',message:'修改失败'})
      }
      this.$notify({type:'success',message:'修改成功'})
    }
  }
}
</script>

<style scoped>

</style>
